import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
from dat1.Mysql import Mysql
from selenium.webdriver.common.keys import Keys

class A3mall(unittest.TestCase):

    def setUp(self) -> None:
        print('start case')
        self.driver = webdriver.Edge()
        # self.driver.maximize_window()
        self.driver.get('http://10.59.9.14:7003/')
        self.db = Mysql(host='10.59.9.14',user='root',passwoord='yidong666',database='a3mall')

    def tearDown(self) -> None:
        time.sleep(6)
        self.driver.quit()
        print('end case')

    def test_A3mall_01(self):
        #点击登录
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        #输入用户名和密码
        self.driver.find_element(By.NAME, 'username').send_keys('15077899457')
        self.driver.find_element(By.NAME, 'password').send_keys('111111')
        time.sleep(15)
        #点击登录按钮
        self.driver.find_element(By.CSS_SELECTOR, '.finish-btn').click()
        time.sleep(4)
        #断言页面用户名与数据库的用户名
        dy1 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]').text
        print(dy1)
        resulf = self.db.chaxun(f'select nickname from mall_users where mobile={15077899457}')
        print(resulf[0][0])
        self.assertIn(resulf[0][0],dy1)
        #断言登录金额
        dy2 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text
        print(dy2)
        numdy2 = dy2.split()[1]
        print(numdy2)
        resulf1 = self.db.chaxun(f'select amount from mall_users where mobile={15077899457}')
        print(resulf1)
        print(resulf1[0][0])
        unm = resulf1[0][0]
        print(type(unm))
        self.assertEqual(float(resulf1[0][0]),float(numdy2))




if __name__ == '__main__':
    unittest.main()


